package com.boyadegroot.divelog.models;

import android.os.Parcel;
import android.os.Parcelable;
import android.support.annotation.NonNull;

public class DiveLocation implements Parcelable, Comparable<DiveLocation> {

    private static final String TAG = DiveLocation.class.getName();

    private long mId;
    private String mName;
    private DiveCountry mCountry;
    private double mLatitude;
    private double mLongitude;

    public DiveLocation() {}

    public DiveLocation(long id, String name, DiveCountry country, double latitude, double longitude) {
        this.setId(id);
        this.setName(name);
        this.setCountry(country);
        this.setLatitude(latitude);
        this.setLongitude(longitude);
    }

    public long getId() {
        return mId;
    }

    public void setId(long id) {
        this.mId = id;
    }

    public String getName() {
        return mName;
    }

    public void setName(String name) {
        this.mName = name;
    }

    public DiveCountry getCountry() {
        return mCountry;
    }

    public void setCountry(DiveCountry country) {
        this.mCountry = country;
    }

    public double getLatitude() {
        return mLatitude;
    }

    public void setLatitude(double latitude) {
        this.mLatitude = latitude;
    }

    public double getLongitude() {
        return mLongitude;
    }

    public void setLongitude(double longitude) {
        this.mLongitude = longitude;
    }

    @Override
    public int compareTo(@NonNull DiveLocation another) {
        return this.mName.compareTo(another.mName);
    }

    @Override
    public String toString() {
        return getName();
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeLong(mId);
        dest.writeString(mName);
        dest.writeParcelable(mCountry, flags);
        dest.writeDouble(mLatitude);
        dest.writeDouble(mLongitude);
    }

    public static final Parcelable.Creator<DiveLocation> CREATOR = new Parcelable.Creator<DiveLocation>() {

        public DiveLocation createFromParcel(Parcel in) {
            return new DiveLocation(in);
        }

        public DiveLocation[] newArray(int size) {
            return new DiveLocation[size];
        }
    };

    private DiveLocation(Parcel in) {
        mId = in.readLong();
        mName = in.readString();
        mCountry = in.readParcelable(DiveCountry.class.getClassLoader());
        mLatitude = in.readDouble();
        mLongitude = in.readDouble();
    }
}
